<template>
  <div class="login">
    <div class="login-box">
      <h2>邵阳</h2>
      <el-form ref="form" :model="loginForm" label-width="80px">
        <el-form-item label="用户账号:">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="用户密码:">
          <el-input v-model="loginForm.password"></el-input>
        </el-form-item>
        <div class="btns">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="default">重置</el-button>
          <a href="#" @click.stop="register()">注册</a>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {Login} from '@/api/loginAPI'
import {GoRegister} from '@/api/index'
export default {
    data() {
        return {
            loginForm:{
                username:'admin',
                password:'123456'
            }
        }
    },
    methods:{
        async login(){
            const {data:res}=await Login(this.loginForm)
            console.log(res)
            if(res.status==200){
              localStorage.setItem('userInfo',JSON.stringify(res))
              this.$router.push('/home')
            }
        },
        // 注册
        async register(){
          const {data:res}=await GoRegister(this.loginForm)
          console.log(res)
        }
    },
    created(){
     
    }

}
</script>

<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;
  background: #93defe;
  display: flex;
  align-items: center;
  justify-content: center;
  .login-box {
    width: 400px;
    height: 350px;
    background: #fff;
    border-radius: 10px;
    text-align: center;
    h2 {
      text-align: center;
    }
    .el-form-item{
        margin: 20px;
    }
    .btns{
        margin-top: 50px;
        // border: 1px solid #000;
    }
  }
}
</style>
